package com.zut.dao.impl;

import com.zut.dao.FoodCategoryDao;
import com.zut.pojo.Food;
import com.zut.pojo.FoodCategory;
import com.zut.utils.DruidUtil;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

/**
 * @author 张晨
 * @date 2024/9/13 9:55
 * @desc
 */
public class FoodCategoryDaoImpl implements FoodCategoryDao {
    private JdbcTemplate jdbcTemplate = new JdbcTemplate(DruidUtil.getDataSource());


    @Override
    public List<FoodCategory> selectByShopId(int shopId) {
        String sql ="select * from food_category where shop_id = ?";
        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(FoodCategory.class),shopId);
    }

    @Override
    public Integer updateById(FoodCategory foodCategory) {
        String sql = "update food_category set category_name = ? where category_id = ?";
        return jdbcTemplate.update(sql,foodCategory.getCategoryName(),foodCategory.getCategoryId());
    }

    @Override
    public Integer deleteById(Integer categoryId) {
        String sql = "delete from food_category where category_id = ?";
        return jdbcTemplate.update(sql,categoryId);
    }

    @Override
    public Integer insert(FoodCategory foodCategory) {
        String sql = "insert into food_category(category_name,shop_id) values(?,?)";
        return jdbcTemplate.update(sql,foodCategory.getCategoryName(),foodCategory.getShopId());
    }
}
